import MattertagsData from "../data/MattertagsData"
import MattertagsViewData from "../data/MattertagsViewData"
import { TagDescriptionChunkType } from "../enum/tagChunkType.enum"
import { MattertagNavigatedMessage, MattertagViewedMessage } from "../message/mattertag.message"
interface item {
  msgType: typeof MattertagNavigatedMessage | typeof MattertagViewedMessage
  func: Function
}
export default class MattertagDataAnalytics {
  handlers: item[]
  constructor() {
    this.handlers = [
      {
        msgType: MattertagNavigatedMessage,
        func: (e, t, i) => {
          const n = i.tryGetData(MattertagsData),
            o = i.tryGetData(MattertagsViewData)
          if (!n || !o) return
          const l = n.getTagCount(),
            c = o.getVisitedTags().length,
            h = o.getViewedTagCount(),
            d = n.getTag(t.sid)
          d &&
            e.track("tag_opened", {
              tag_count: l,
              tag_id: t.sid,
              tags_visited: c,
              tag_view_count: h,
              has_media: d.mediaType !== TagDescriptionChunkType.none
            })
        }
      },
      {
        msgType: MattertagViewedMessage,
        func: (e, t, i) => {
          const n = i.tryGetData(MattertagsData),
            o = i.tryGetData(MattertagsViewData)
          if (!n || !o) return
          const a = n.getTagCount(),
            l = o.getVisitedTags().length,
            c = o.getViewedTagCount(),
            h = n.getTag(t.sid)
          if (h) {
            const i = {
              mattertag_sid: t.sid,
              mattertag_view: t.view,
              mattertag_media: h.mediaType,
              mattertags_count: a,
              mattertags_total_views: c,
              mattertags_visited: l
            }
            e.track("mattertag_view", i)
          }
        }
      }
    ]
  }
}
// export default {
//   V: n,
//   s: MattertagDataAnalytics
// }
